#! /bin/bash

# 需要设置的主机名，以空格间隔
hosts="e131 e132"

for host in $hosts;
do
  echo $host;
# 关闭防火墙
  ssh $host "systemctl stop firewalld & systemctl disable firewalld";
# 禁用swap
  ssh $host "swapoff -a & sed -i 's/.*swap.*/#&/' /etc/fstab";
# 关闭selinux
  ssh $host "setenforce  0 & sed -i \"s/^SELINUX=enforcing/SELINUX=disabled/g\" /etc/sysconfig/selinux & sed -i \"s/^SELINUX=enforcing/SELINUX=disabled/g\" /etc/selinux/config & sed -i \"s/^SELINUX=permissive/SELINUX=disabled/g\" /etc/sysconfig/selinux & sed -i \"s/^SELINUX=permissive/SELINUX=disabled/g\" /etc/selinux/config";
# 设置ip 转发
ssh $host "echo \"1\" > /proc/sys/net/ipv4/ip_forward  & modprobe br_netfilter & cat <<EOF >  /etc/sysctl.d/k8s.conf
  net.bridge.bridge-nf-call-ip6tables = 1
  net.bridge.bridge-nf-call-iptables = 1
EOF"; 
  ssh $host "sysctl -p /etc/sysctl.d/k8s.conf & ls /proc/sys/net/bridge";

# 设置内核参数,文件打开数

ssh -T $host <<EOF
echo "* soft nofile 65536" >> /etc/security/limits.conf
echo "* hard nofile 65536" >> /etc/security/limits.conf
echo "* soft nproc 65536"  >> /etc/security/limits.conf
echo "* hard nproc 65536"  >> /etc/security/limits.conf
echo "* soft  memlock  unlimited"  >> /etc/security/limits.conf
echo "* hard memlock  unlimited"  >> /etc/security/limits.conf
EOF

done
